package com.example.forum.auto.tests;

import com.example.forum.auto.common.BrowserName;
import com.example.forum.auto.common.Utils;
import lombok.SneakyThrows;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.springframework.util.StringUtils;

/**
 * @author hanzishuai
 * Blog :  https://blog.csdn.net/qrwitu142857
 * @date 2025/5/15 19:30
 * @Description
 */
public class ArticleDetailPage extends Utils {

    public static final String url = "http://82.157.200.90:58081/index.html";

    public ArticleDetailPage(BrowserName browserName) {
        super(url, browserName);
    }

    public ArticleDetailPage() {
        super(url);
    }


    @SneakyThrows
    public void checkPageRight() {
        driver.findElement(By.cssSelector("#btn_details_send_message"));
        driver.findElement(By.cssSelector("#details_btn_like_count"));
        driver.findElement(By.cssSelector("#details_btn_article_reply"));
    }


    private void sendMessage(String content) {
        WebElement element = driver.findElement(By.cssSelector("#btn_details_send_message"));
        wait.until(ExpectedConditions.elementToBeClickable(element));
        element.click();

        WebElement element1 = driver.findElement(By.cssSelector("#index_message_receive_content"));
        wait.until(ExpectedConditions.elementToBeClickable(element1));
        if(StringUtils.hasLength(content)) {
            element1.sendKeys(content);
        }

        driver.findElement(By.cssSelector("#btn_index_send_message")).click();
    }

    public void sendMessageFail() {
        sendMessage(null);
        sendMessage("");
    }

    public void sendMessageSuccess() {
        sendMessage("test");
    }

}
